package com.sxbbc.common.core.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxbbc.common.basics.utils.date.DateUtil;
import com.sxbbc.common.core.entity.jz.ChickenFund;
import com.sxbbc.common.core.mapper.jz.ChickenFundMapper;
import com.sxbbc.common.core.service.IChickenFundService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxbbc.common.core.utils.BasePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 基金表 服务实现类
 * </p>
 *
 * @author
 * @since 2020-04-26
 */
@Service
public class ChickenFundServiceImpl extends ServiceImpl<ChickenFundMapper, ChickenFund> implements IChickenFundService {

    @Autowired
    private ChickenFundMapper chickenFundMapper;

    @Override
    public List<ChickenFund> selectReleaseFund() {
        return chickenFundMapper.selectReleaseFund();
    }

    @Override
    public int releaseFund(List<String> paycodes) {
        return chickenFundMapper.releaseFund(paycodes);
    }

    @Override
    public IPage<ChickenFund> selectChickenFundList(BasePage<ChickenFund> page, ChickenFund chickenFund) {
        IPage<ChickenFund> fundIPage = chickenFundMapper.selectChickenFundList(page, chickenFund);
//        if(fundIPage.getSize()>0){
//            for (ChickenFund record : fundIPage.getRecords()) {
//            }
//        }
        return fundIPage;
    }

    @Override
    public int setTime() {
        return chickenFundMapper.setTime();
    }

    @Override
    public HashMap<String, Object> queryTotalFundByDate(String queryTmie) {
        String startTime = null;
        String endTime = null;
        HashMap<String, Object> hashMap = new HashMap<>();
        if (org.apache.commons.lang3.StringUtils.isNotBlank(queryTmie)) {
            String[] times = queryTmie.split("~");
            startTime = times[0];
            endTime = times[1];
            hashMap.put("queryTmie", queryTmie);
        } else {
            startTime = DateUtil.getInstance().toDateString(new Date());
            endTime = startTime;
            hashMap.put("queryTmie", startTime + "~" + endTime);
        }
        BigDecimal totalMoney = chickenFundMapper.queryTotalFundByDate(startTime, endTime);
        hashMap.put("totalMoney", totalMoney);
        return hashMap;
    }

    @Override
    public void handleLaterDay(List<Integer> ids, int day) {
        chickenFundMapper.handleLaterDay(ids,day);
    }
}
